#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<sys/types.h>
#include<netinet/in.h>
#include<arpa/inet.h>
#include<sys/socket.h>

// 客户端实现代码
int main(){
    int sfd = socket(AF_INET,SOCK_STREAM,0);
    if(sfd<0){
        perror("socket build failed;");
        return -1;
    }
    struct sockaddr_in addr;
    addr.sin_family = AF_INET;
    addr.sin_port = htons(8888);
    inet_pton(AF_INET,"127.0.0.1",&addr.sin_addr.s_addr);
    int ret = connect(sfd,(struct sockaddr *)&addr,sizeof(addr));
    if(ret<0){
        perror("connect error;");
        close(sfd);
        return -1;
    }
    int n=0;
    char buf[256];
    for(;;){
        memset(buf,0x00,sizeof(buf));
        n = read(STDIN_FILENO,buf,sizeof(buf));
        write(sfd,buf,n);
        memset(buf,0x00,sizeof(buf));
        n = read(sfd,buf,sizeof(buf));
        if(n<=1){
            break;
        }
        printf("get fedback msg:%s",buf);
    }
    close(sfd);
    return 0;

}